# Create your models here.


from django.db import models


# 患者来源模型
class SourceModel(models.Model):
    sname = models.CharField(max_length=50, unique=True, verbose_name='患者来源名称')

    def __str__(self):
        return self.sname

    class Meta:
        db_table = 'source'


class AppointmentModel(models.Model):
    aname = models.CharField(max_length=50, verbose_name="预约状态")

    def __str__(self):
        return self.aname

    class Meta:
        db_table = 'appointment'







# 患者模型
class PatientModel(models.Model):
    pname = models.CharField(max_length=50, verbose_name='患者名称')
    sex = models.CharField(max_length=20, verbose_name='性别')
    dday = models.DateField(verbose_name='预约日期')
    phone = models.CharField(max_length=20, verbose_name='电话')
    source = models.ForeignKey(SourceModel, on_delete=models.CASCADE, verbose_name='患者来源')
    content = models.CharField(max_length=200, verbose_name='服务内容')
    appointment = models.ForeignKey(AppointmentModel, on_delete=models.CASCADE, verbose_name='预约状态')
    writeoff = models.CharField(max_length=20, verbose_name='凭证核销')

    def __str__(self):
        return self.pname

    class Meta:
        db_table = 'patient'

# 分诊状态
class TriageModel(models.Model):
    tname = models.CharField(max_length=50,verbose_name="分诊状态")
    def __str__(self):
        return self.tname
    class Meta:
        db_table = 'triage'



# 挂号预约
class BookingModel(models.Model):
    bname = models.CharField(max_length=20,verbose_name="患者名称")
    sex = models.CharField(max_length=20, verbose_name='性别')
    age = models.CharField(max_length=20,verbose_name='年龄')
    dangan = models.CharField(max_length=20,verbose_name="档案号")
    dday = models.DateField(verbose_name='预约日期')
    source = models.ForeignKey(SourceModel, on_delete=models.CASCADE, verbose_name='预约医生')
    Triage = models.ForeignKey(TriageModel,on_delete=models.CASCADE, verbose_name='分诊状态')
    appointment = models.ForeignKey(AppointmentModel, on_delete=models.CASCADE, verbose_name='预约状态')
    writeoff = models.CharField(max_length=20, verbose_name='病情描述')

    def __str__(self):
        return self.bname
    class Meta:
        db_table = 'booking'

